Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | 'use client'; import React from 'react'; import { Card, CardContent } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Avatar, AvatarFallback } from '@/components/ui/avatar'; import { MessageSquare, Clock, AlertCircle, CheckCircle, XCircle, Pause, Calendar, Hash, Bell } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useTranslation } from 'react-i18next'; interface Ticket { id: number; ticket_number: string; title: string; description: string; status: string; priority: string; creator_username: string; created_at: string; updated_at: string; has_unread: boolean; unread_count: number; } interface TicketCardProps { ticket: Ticket; onOpenChat: (ticketId: number) => void; className?: string; } const statusConfig = { open: { icon: AlertCircle, color: 'text-primary', bgColor: 'bg-primary/10', borderColor: 'border-primary/20', labelKey: 'tickets.status.open' }, in_progress: { icon: Clock, color: 'text-yellow-600', bgColor: 'bg-yellow-500/10', borderColor: 'border-yellow-500/20', labelKey: 'tickets.status.in_progress' }, resolved: { icon: CheckCircle, color: 'text-green-600', bgColor: 'bg-green-500/10', borderColor: 'border-green-500/20', labelKey: 'tickets.status.resolved' }, closed: { icon: XCircle, color: 'text-muted-foreground', bgColor: 'bg-muted', borderColor: 'border-muted', labelKey: 'tickets.status.closed' }, on_hold: { icon: Pause, color: 'text-purple-600', bgColor: 'bg-purple-500/10', borderColor: 'border-purple-500/20', labelKey: 'tickets.status.on_hold' } }; const priorityConfig = { low: { color: 'bg-muted text-muted-foreground border-muted', icon: '●', iconColor: 'text-muted-foreground' }, medium: { color: 'bg-yellow-500/10 text-yellow-600 border-yellow-500/20', icon: '●', iconColor: 'text-yellow-600' }, high: { color: 'bg-orange-500/10 text-orange-600 border-orange-500/20', icon: '●', iconColor: 'text-orange-600' }, urgent: { color: 'bg-destructive/10 text-destructive border-destructive/20', icon: '●', iconColor: 'text-destructive' } }; export default function TicketCard({ ticket, onOpenChat, className }: TicketCardProps) { const { t } = useTranslation(); const status = statusConfig[ticket.status as keyof typeof statusConfig] || statusConfig.open; const priority = priorityConfig[ticket.priority as keyof typeof priorityConfig] || priorityConfig.medium; const StatusIcon = status.icon; const getUserInitials = (username: string) => { return username.split(' ').map(n => n[0]).join('').toUpperCase().slice(0, 2); }; const formatTimeAgo = (dateString: string) => { const date = new Date(dateString); const now = new Date(); const diffInMinutes = Math.floor((now.getTime() - date.getTime()) / (1000 * 60)); if (diffInMinutes < 1) return t('ticketCard.justNow'); if (diffInMinutes < 60) return t('feedback.time.minutesAgo', { count: diffInMinutes }); const diffInHours = Math.floor(diffInMinutes / 60); if (diffInHours < 24) return t('feedback.time.hoursAgo', { count: diffInHours }); const diffInDays = Math.floor(diffInHours / 24); if (diffInDays < 7) return t('feedback.time.daysAgo', { count: diffInDays }); return date.toLocaleDateString(); }; const truncateText = (text: string, maxLength: number) => { if (text.length <= maxLength) return text; return text.substring(0, maxLength) + '...'; }; return ( <Card className={cn( 'group hover:shadow-md transition-all duration-200 cursor-pointer border-l-4', status.borderColor, ticket.has_unread && 'ring-2 ring-primary/20', className )}> <CardContent className="p-6"> {/* Header */} <div className="flex items-start justify-between mb-4"> <div className="flex items-center gap-3"> <div className={cn('p-2 rounded-full', status.bgColor)}> <StatusIcon className={cn('h-4 w-4', status.color)} /> </div> <div> <div className="flex items-center gap-2 mb-1"> <span className="font-mono text-sm text-muted-foreground flex items-center gap-1"> <Hash className="h-3 w-3" /> {ticket.ticket_number} </span> {ticket.has_unread && ( <div className="relative"> <Bell className="h-4 w-4 text-destructive animate-pulse" /> <div className="absolute -top-1 -right-1 w-2 h-2 bg-destructive rounded-full"></div> </div> )} </div> <h3 className="font-semibold text-foreground group-hover:text-primary transition-colors"> {truncateText(ticket.title, 50)} </h3> </div> </div> <div className="flex items-center gap-2"> <Badge variant="outline" className={cn('text-xs border', status.color, status.bgColor)}> {t(status.labelKey)} </Badge> <Badge variant="outline" className={cn('text-xs border', priority.color)}> <span className={cn('mr-1', priority.iconColor)}>{priority.icon}</span> {t(`ticketCard.priority.${ticket.priority}`, { defaultValue: ticket.priority.toUpperCase() })} </Badge> </div> </div> {/* Description */} <p className="text-muted-foreground text-sm mb-4 leading-relaxed"> {truncateText(ticket.description, 120)} </p> {/* Footer */} <div className="flex items-center justify-between"> <div className="flex items-center gap-4 text-xs text-muted-foreground"> <div className="flex items-center gap-2"> <Avatar className="h-6 w-6"> <AvatarFallback className="bg-muted text-muted-foreground text-xs"> {getUserInitials(ticket.creator_username)} </AvatarFallback> </Avatar> <span>{ticket.creator_username}</span> </div> <div className="flex items-center gap-1"> <Calendar className="h-3 w-3" /> <span>{formatTimeAgo(ticket.created_at)}</span> </div> <div className="flex items-center gap-1"> <Clock className="h-3 w-3" /> <span>{t('ticketCard.updatedAt', { time: formatTimeAgo(ticket.updated_at) })}</span> </div> </div> <Button onClick={() => onOpenChat(ticket.id)} variant={ticket.has_unread ? "default" : "outline"} size="sm" className={cn( 'transition-all duration-200', ticket.has_unread && 'bg-primary hover:bg-primary/90 text-primary-foreground animate-pulse shadow-lg' )} > <div className="relative flex items-center gap-2"> <MessageSquare className="h-4 w-4" /> {ticket.has_unread ? ( <> <span className="font-medium">{t('ticketCard.newCount', { count: ticket.unread_count })}</span> <div className="absolute -top-1 -right-1 w-2 h-2 bg-primary-foreground rounded-full"></div> </> ) : ( <span>{t('ticketCard.chat')}</span> )} </div> </Button> </div> {/* Unread indicator bar */} {ticket.has_unread && ( <div className="mt-4 pt-4 border-t border-primary/20"> <div className="flex items-center gap-2 text-primary"> <div className="w-2 h-2 bg-primary rounded-full animate-pulse"></div> <span className="text-xs font-medium"> {ticket.unread_count === 1 ? t('ticketCard.unreadMessageSingle', { count: ticket.unread_count }) : t('ticketCard.unreadMessagePlural', { count: ticket.unread_count })} </span> </div> </div> )} </CardContent> </Card> ); } |